package seu.evaluation.metric;


/**
 * 
 * @author samantha
 * Loose Class Cohesion（宽松内聚性）：直接关联+关联的传递闭包
 * NIC:关联的传递闭包
 *
 */
public class CohesionLCC extends MaintainabilityMetricStrategy{
	
	public CohesionLCC(){}

	@Override
	protected String getType() {	
		return "CohesionLCC";
	}
	

	@Override
	protected double differentMetricMethod(MaintainabilityEntity entity) {		
		int size = entity.getS();
		if( size <=1 )
			return -1;
		int a[][] = entity.getTransitiveClosure();
		for( int j=0; j<size; j++ ){
			for( int i=0; i<size; i++){
				if( i!=j && a[i][j]>=1 ){
					for( int k=0; k<size; k++){
						if( i!=k )
							a[i][k] += ( a[i][j] * a[j][k] );	
					}
				}
			}
		}	
		
		
		double result = 0;
		for( int i=0; i<size; i++)
			for( int j=0; j<size; j++)
				result+=a[i][j];
		double temp = size * (size-1) /2;
		result = result / temp;	
		
		return result;
	}

	@Override
	protected void preprocess() {
		// TODO Auto-generated method stub
		
	}



}
